package com.mall.coupon.server.controller;

import com.mall.common.core.domain.Result;
import com.mall.coupon.common.domain.domain.Coupon;
import com.mall.coupon.common.domain.domain.UserCouponMiddle;
import com.mall.coupon.server.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName couponController
 * @Description 描述
 * @Author Qiu Feng
 * @Date 2025/1/13 14:39
 */
@RestController
@RequestMapping("/coupon")
public class couponController {
    @Autowired
    private CouponService couponService;


    /**
     * 用户领取优惠券
     */
    @PostMapping("/{couponId}")
    public void userCouponAdd(@PathVariable Long couponId) {
        couponService.userCouponAdd(couponId);
    }

    /**
     * 用户已领取优惠卷列表
     */
    @GetMapping("/userCouponMiddleList")
    public Result<List<Coupon>> userCouponMiddleList() {
        List<UserCouponMiddle> userCouponMiddles = couponService.userCouponMiddleList();
        Result success = Result.success(userCouponMiddles);
        return success;
    }

    /**
     * 结算选择可用优惠券列表
     */
    @GetMapping("/settlementCouponList")
    public Result<List<Coupon>> settlementCouponList() {
        List<Coupon> coupons = couponService.settlementCouponList();
        Result<List<Coupon>> success = Result.success(coupons);
        return success;
    }

//    @GetMapping("/settlementList/{skuId}")
//    public Result<List<Coupon>> filteredCoupons(@PathVariable Long skuId){
//        List<Coupon> coupons = couponService.filteredCoupons(skuId);
//        Result<List<Coupon>> success = Result.success(coupons);
//        return success;
//    }

//    @GetMapping("/settlementList/{skuId}")
//    public Result<List<UserCouponMiddle>> filteredCoupon(@PathVariable List<UserCouponMiddle> userCouponMiddles, @PathVariable List<SkuCouponMiddle> skuCouponMiddles,@PathVariable Long skuId){
//        List<UserCouponMiddle> userCouponMiddles1 = couponService.filteredCoupon(userCouponMiddles, skuCouponMiddles, skuId);
//        Result<List<UserCouponMiddle>> success = Result.success(userCouponMiddles1);
//        return success;
//    }


    /**
     * 优惠券已使用状态修改
     */
    @PutMapping("/update/{id}")
    public void updateUserCouponMiddleStatus(@PathVariable Integer id) {
        couponService.updateUserCouponMiddleStatus(id);
    }
}
